from app.configs.default import Config
import datetime
from datetime import timedelta


class ProConfig(Config):
    DEBUG = False

    # APScheduler 配置
    ENABLE_KAFKA = True

    # 控制所有定时任务的开启
    SCHEDULE_SWITCH = True
    SCHEDULER_API_ENABLED = True

    # simulation 还需要设置 deamon.py 里面的具体时间节点
    SHAOJIE_SIMULATION_ENABLED = False
    GAOLU_SIMULATION_ENABLED = False
    HANFAN_SIMULATION_ENABLED = False

    INFLUXDB_HOST = '192.168.40.214'
    INFLUXDB_PORT = 8086
    INFLUXDB_USERNAME = 'admin'
    INFLUXDB_PASSWORD = 'BICI123456'
    INFLUXDB_DATABASE = 'bfbd2023'

    # 秒级别
    if GAOLU_SIMULATION_ENABLED:
        GAOLU_INTERVAL = 5
    else:
        GAOLU_INTERVAL = 3600  # 1 小时

    if SHAOJIE_SIMULATION_ENABLED:
        SHAOJIE_INTERVAL = 5
    else:
        SHAOJIE_INTERVAL = 5

    # 秒级别
    if HANFAN_SIMULATION_ENABLED:
        HANFAN_INTERVAL = 5
    else:
        HANFAN_INTERVAL = 3600  # 20分钟

    HANFAN_DUMP_DATA_INTERVAL = 1800  # 30分钟

    # cron表达式
    GAOLU_BANBIE_SCORE_BACKTRACKING = "0,8,16"

    JOBS = [
        {
            'id': 'shaojie_model_predict_online',
            'func': 'app.services.schedule.deamon:shaojie_model_predict_online',
            'trigger': 'interval',
            'seconds': SHAOJIE_INTERVAL
        },
        {
            'id': 'gaolu_model_predict',
            'func': 'app.services.schedule.deamon:gaolu_model_predict_online',
            'trigger': 'cron',
            'hour': '*',
            'minute': '10',
            'second': '10'
            # 'seconds': GAOLU_INTERVAL,
            # 'next_run_time': datetime.datetime.now() + datetime.timedelta(seconds=10)  # job在2分钟后立即运行
        },
        {
            'id': 'hanfan_model_predict',
            'func': 'app.services.schedule.deamon:hanfan_model_predict_online',
            'trigger': 'interval',
            'seconds': HANFAN_INTERVAL,
            'next_run_time': datetime.datetime.now() + datetime.timedelta(seconds=60)  # job在2分钟后立即运行
        },
        {
            'id': 'gaolu_banbie_backtracking_data',
            'func': 'app.services.schedule.deamon:gaolu_banbie_backtracking_data',
            'args': (),
            'trigger': 'cron',
            'hour': GAOLU_BANBIE_SCORE_BACKTRACKING
        },
        {
            'id': 'dump_hanfan_data',
            'func': 'app.services.schedule.deamon:dump_hanfan_data',
            'trigger': 'interval',
            'seconds': HANFAN_DUMP_DATA_INTERVAL,
            'next_run_time': datetime.datetime.now() + datetime.timedelta(seconds=60)  # job在10分钟后立即运行
        },
        {
            'id': 'dump_lugang_data',
            'func': 'app.services.schedule.deamon:dump_lugang_data',
            'trigger': 'interval',
            'seconds': 10,
            'args': (),
            # 'next_run_time': datetime.datetime.now()  # job在10分钟后立即运行
        },

        {
            'id': 'dump_lugang_qinshi_data',
            'func': 'app.services.schedule.deamon:dump_lugang_qinshi_data',
            'trigger': 'interval',
            'seconds': 30,
            'args': (),
            # 'next_run_time': datetime.datetime.now()  # job在10分钟后立即运行
        }
        ,
        {
            'id': 'dump_lugang_qinshi_model_data',
            'func': 'app.services.schedule.deamon:dump_lugang_qinshi_model_data',
            'trigger': 'interval',
            'seconds': 30,
            'args': (),
            # 'next_run_time': datetime.datetime.now()  # job在10分钟后立即运行
        }
        ,
        {
            'id': 'cal_lugang_data_dist',
            'func': 'app.services.schedule.deamon:cal_lugang_data_dist',
            'trigger': 'interval',
            'seconds': 30,
            'args': (),
            # 'next_run_time': datetime.datetime.now()  # job在10分钟后立即运行
        }
        ,
        {
            'id': 'dump_lugang_activeness_long',
            'func': 'app.services.schedule.deamon:dump_lugang_activeness_long',
            'trigger': 'interval',
            'seconds': 30,
            'args': (),
            # 'next_run_time': datetime.datetime.now()  # job在10分钟后立即运行
        }
        ,
        {
            'id': 'dump_lugang_activeness_predict_long',
            'func': 'app.services.schedule.deamon:dump_lugang_activeness_predict_long',
            'trigger': 'interval',
            'seconds': 30,
            'args': (),
            # 'next_run_time': datetime.datetime.now()  # job在10分钟后立即运行
        },

        {
            'id': 'dump_lugang_activeness_short',
            'func': 'app.services.schedule.deamon:dump_lugang_activeness_short',
            'trigger': 'interval',
            'seconds': 60,
            'args': (),
            # 'next_run_time': datetime.datetime.now()  # job在10分钟后立即运行
        },
        {
            'id': 'dump_lugang_activeness_predict_short',
            'func': 'app.services.schedule.deamon:dump_lugang_activeness_predict_short',
            'trigger': 'interval',
            'seconds': 60,
            'args': (),
            # 'next_run_time': datetime.datetime.now()  # job在10分钟后立即运行
        },
        {
            'id': 'cal_gaolu_diagnose',
            'func': 'app.services.schedule.deamon:cal_gaolu_diagnose',
            'trigger': 'interval',
            'seconds': 30,
            'args': (),
            'next_run_time': datetime.datetime.now() + timedelta(seconds=10)  # job在10s后立即运行
        },
        {
            'id': 'cal_luzha_hanfan_data',
            'func': 'app.services.schedule.deamon:cal_luzha_hanfan_data',
            'trigger': 'interval',
            'seconds': 30,
            'args': (),
            'next_run_time': datetime.datetime.now() + timedelta(seconds=10)  # job在10s后立即运行
        },
        {
            'id': 'data_integration',
            'func': 'app.services.schedule.deamon:data_integration',
            'trigger': 'interval',
            'seconds': 3600,
            'args': (),
            'next_run_time': datetime.datetime.now() + timedelta(seconds=10)  # job在10s后立即运行
        },
        {
            'id': 'zhapi_data_dump',
            'func': 'app.services.schedule.deamon:data_integration',
            'trigger': 'interval',
            'seconds': 3600,
            'args': (),
            'next_run_time': datetime.datetime.now() + timedelta(seconds=10)  # job在10s后立即运行
        }
    ]
